<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户展示界面</title>
</head>
<style>
    td,
    tr,
    th {
        border: 1px solid;
    }

    .add {
        margin-left: 135px;
    }
</style>

<body>
    <div id="app">
        <div id="app-1">
            <input type="text" @input="search" placeholder="请输入关键字">
            <input type="button" @click="add" value="添加" class="add">
        </div>
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tr v-for="(item,index) of lists">
                <td>{{index+1}}</td>
                <td>{{item.username}}</td>
                <td>{{item.password}}</td>
                <td>
                    <input type="button" @click="up" value="修改">
                    <input type="button" @click="del" value="删除">
                </td>
            </tr>
        </table>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            lists: [],
            list: [
                {
                    username: '爱探险的哆啦',
                    password: '1234567890'
                },
                {
                    username: '捣蛋鬼',
                    password: '1234567890'
                },
                {
                    username: '西伯利亚大尾巴狼',
                    password: '1234567890'
                },
                {
                    username: '芝士莓莓',
                    password: '1234567890'
                },
                {
                    username: '香草巧克力',
                    password: '1234567890'
                }
            ]
        },
        created() {// 生命周期函数
            this.setLists(this.list)
        },
        methods: {
            setLists(arr) {
                // JSON.parse()通常用于与服务端交换数据
                // 在接收服务器数据时一般是字符串
                // 使用JSON.stringify()方法处理以上数据，将其转换为字符串
                this.lists = JSON.parse(JSON.stringify(arr));
            }
        }
    })
</script>

</html>